package com.xl.rentkeeper.act.kanfang;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;

import com.xl.rentkeeper.App;
import com.xl.rentkeeper.R;
import com.xl.rentkeeper.act.BaseAct;
import com.xl.rentkeeper.business.OrderLogic;
import com.xl.rentkeeper.entity.Order;
import com.xl.rentkeeper.log.QLog;
import com.xl.rentkeeper.util.DialogUtil;
import com.xl.rentkeeper.view.TitleBar;

/**
 * Created by Administrator on 2015/8/17.
 */
public class CancelOrderRoomAct extends BaseAct {
    private EditText mETReason;
    private int id;
    private long leadStewardId;
    private Dialog mDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cancel_room);

        TitleBar tb = (TitleBar) findViewById(R.id.tb);
        setTranslucentStatus();
        initTitleBar(tb);
        initView();
    }

    private void initView() {

        mETReason = (EditText) findViewById(R.id.et_reason);

        Intent intent = this.getIntent();
        Order msg = (Order) intent.getSerializableExtra("msg");
        id =msg.id;
        leadStewardId =msg.viewOrder.leadStewardId;
        QLog.d("TAG", "id:" + id + " id1 " + leadStewardId);
    }

    public void submit(View v){
        String mReason = mETReason.getText().toString().trim();
        if (mETReason.length() < 5){
            App.showToast("描述不能低于5个字");
            return;
        }
        mDialog = DialogUtil.showProgressDialog(this, R.string.loading);
        OrderLogic.getInstance().reserveRoom(id, false, null, mReason);
    }

    public void selectReason(View v){
        switch (v.getId()){
            case R.id.bt_reason1:
                mETReason.getText().append(" 价格不合适 ");
                break;
            case R.id.bt_reason2:
                mETReason.getText().append(" 房源不合适 ");
                break;
            case R.id.bt_reason3:
                mETReason.getText().append(" 室友性别原因 ");
                break;
            case R.id.bt_reason4:
                mETReason.getText().append(" 交通不便利 ");
                break;
            case R.id.bt_reason5:
                mETReason.getText().append(" 不着急租房 ");
                break;
            case R.id.bt_reason6:
                mETReason.getText().append(" 希望短租 ");
                break;
        }
    }

    public String[] monitorEvents() {
        return new String[]{PMS_LOGIC_ReserveRoom};
    }

    @Override
    public void onEvent(String event, boolean ret,String errInfo, Object[] data) {
        super.onEvent(event, ret,errInfo, data);
        if (event.equals(OrderLogic.PMS_LOGIC_ReserveRoom)){
            if(mDialog!=null && mDialog.isShowing())mDialog.dismiss();
            if (ret){
                setResult(110);
                finish();
               /* Intent intent = new Intent(this, NotSignOrderActivity.class);
                startActivity(intent);
                overridePendingTransition(R.anim.base_slide_right_in, R.anim.base_slide_remain);*/
               // App.showToast(R.string.submit_succeed);

            }else {
                App.showToast(R.string.submit_fail);
            }
        }
    }
}
